home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / MOTOR.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  117 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3. motor    proc far
  4.  
  5. intaddr equ 1ch*4        ; timer interrupt address
  6. usraddr equ 63h*4        ; point to first copy of program
  7. whozat    equ 1236H        ; program signature
  8. mcount    equ 440h        ; motor timeout count - BIOS data
  9. mstate    equ 4ffh        ; motor state - in DOS comm area
  10.  
  11. ; Memory-resident program to keep the disk drive motor running. Once
  12. ; started, the drive motor will run indefinitely until another drive is
  13. ; referenced or this program is run again.
  14.  
  15.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  16.     jmp p050        ; transient code
  17.  
  18. signature dw whozat        ; program signature
  19. jumpval dd 0            ; continuation of timer interrupt
  20.  
  21. p000:                ; interrupt code
  22.     push ax         ; save registers
  23.     push ds
  24.     push si
  25.     mov ax,0
  26.     mov ds,ax
  27.     mov si,mstate        ; point to motor state
  28.     mov al,[si]
  29.     cmp al,0
  30.     jz p010         ; don't keep it running
  31.     mov si,mcount        ; point to time out counter
  32.     mov ax,37        ; timeout count - 2 seconds
  33.     mov [si],ax        ; update timeout
  34. p010:    pop si            ; restore registers
  35.     pop ds
  36.     pop ax
  37.     jmp cs:[jumpval]
  38.  
  39. p050:                ; start of transient code
  40.     mov dx,offset copyr
  41.     call p200        ; print copyright message
  42.     mov ax,0
  43.     mov es,ax
  44.     mov di,usraddr+2
  45.     mov ax,es:[di]        ; get prior segment
  46.     mov es,ax
  47.     mov di,offset signature
  48.     mov cx,es:[di]        ; get program's signature
  49.     cmp cx,whozat        ; is it this program?
  50.     jnz p075        ; no - install it
  51.  
  52.     mov di,mstate        ; yes - modify state
  53.     mov ax,0
  54.     mov es,ax
  55.     mov al,es:[di]        ; get state
  56.     xor al,0ffh        ; invert al
  57.     mov es:[di],al
  58.     mov dx,offset msg1
  59.     call p200
  60.     cmp al,0        ; motor off?
  61.     jz p060         ; yes
  62.     mov dx,offset msg1on
  63.     jmp p070
  64. p060:    mov dx,offset msg1off
  65. p070:    call p200
  66.     int 20h         ; terminate
  67.  
  68. p075:    mov ax,0
  69.     mov es,ax
  70.     mov di,intaddr        ; interrupt location
  71.     mov ax,es:[di]        ; get ip of current interrupt
  72.     mov bx,es:[di+2]    ; get cs of current interrupt
  73.     mov si,offset jumpval    ; point to jump value
  74.     mov [si],ax        ; save
  75.     mov [si+2],bx        ;      it
  76.  
  77. p080:    mov ax,0
  78.     mov es,ax
  79.     mov al,0ffh        ; set motor on
  80.     mov di,mstate
  81.     mov es:[di],al
  82.     mov di,intaddr
  83.     mov ax,offset p000    ; get current ip
  84.     mov bx,ds        ; get current cs
  85.  
  86.     cli            ; clear interrupts
  87.     mov es:[di],ax        ; modify
  88.     mov es:[di+2],bx    ;     vector
  89.     mov di,usraddr
  90.     push cs
  91.     pop bx            ; get cs in bx
  92.     mov es:[di+2],bx    ; set segment pointer
  93.     sti            ; set interrupts
  94.  
  95.     mov dx,offset msg1    ; print message
  96.     call p200
  97.     mov dx,offset msg1on
  98.     call p200
  99.     mov dx,offset p050    ; last byte of resident portion
  100.     int 27h         ; terminate
  101.  
  102. p200    proc near        ; print message
  103.     push ax
  104.     mov ah,9
  105.     int 21h
  106.     pop ax
  107.     ret
  108. p200    endp
  109.  
  110. copyr    db 'MOTOR - Copyright 1983 Data Base Decisions',10,13,'$'
  111. msg1    db 'Turning drive motor $'
  112. msg1on    db 'on.$'
  113. msg1off db 'off.$'
  114. motor    endp
  115. cseg    ends
  116. end    motor
  117.